import torch
import numpy as np
import os

try:
    from scripts.toolss import data_compare_np
except Exception as e:
    from toolss import data_compare_up


def do_cmp():
    if not os.path.exists('output/output_o.bin'):
        raise Exception("File Not Found: output/output_o.bin")
    if not os.path.exists('output/golden_o.bin'):
        raise Exception("File Not Found: output/golden_o.bin")
    
    gen_o = (
        np.fromfile('output/output_o.bin', dtype=np.uint16).astype(np.uint32) << 16
    ).view(np.float32)
    golden_o = (
        np.fromfile('output/golden_o.bin', dtype=np.uint16).astype(np.uint32) << 16
    ).view(np.float32)

    threshold = 0.008
    data_compare_np(gen_o, golden_o, diff_thd=threshold, pct_thd=threshold, max_diff_hd=20)

if __name__ == '__main__':
    do_cmp()